package kangbo.studentmanagementsystem;

import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.control.cell.ChoiceBoxTableCell;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.paint.ImagePattern;
import javafx.scene.paint.Paint;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Modality;
import javafx.stage.Stage;



import java.io.IOException;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collections;


public class Homepage<message> extends Application {
    static BorderPane borderPane = new BorderPane();
    static Stage Addstage = new Stage();
    static Stage Reavmpstage = new Stage();
    static Stage Revisestage = new Stage();
    static Stage Deletestage = new Stage();
    static Stage Hintstage = new Stage();


    @Override
    public void start(Stage stage) throws Exception {
        Scene scene = new Scene(borderPane,900,700);
        stage.setTitle("学生信息管理系统");

        //背景图片
        borderPane.setStyle("-fx-background-image: url(" + "file:src/main/java/kangbo/studentmanagementsystem/blackground.png" + "); " +
                "-fx-background-position: center center; " +
                "-fx-background-repeat: stretch;" +
                "-fx-background-color:  transparent;");
        stage.setTitle("学生信息管理系统");
        stage.setResizable(false);
        //**********  主页面  ****************************
//        ImagePattern imagePattern=new ImagePattern(new Image("File:blakeground.png"));
//        borderPane.setBackground(new Background(new BackgroundFill(imagePattern,null,null) ));
        Top();
        Center();
        Bottom();
        Side();
        //***************/*设置绑定stage 防止出现多个页面*/****************************/

        Addstage.initOwner(stage);
        Addstage.initModality(Modality.WINDOW_MODAL);
        Reavmpstage.initOwner(stage);
        Reavmpstage.initModality(Modality.WINDOW_MODAL);
        Revisestage.initOwner(stage);
        Revisestage.initModality(Modality.WINDOW_MODAL);
        Deletestage.initOwner(stage);
        Deletestage.initModality(Modality.WINDOW_MODAL);
        Hintstage.initOwner(stage);
        Hintstage.initModality(Modality.WINDOW_MODAL);
        //*******************************************************
        //初始化Message_gridPane
        new Message_gridPane();



        stage.getIcons().add(new Image("file:title/person.png"));
        stage.setScene(scene);
        stage.show();
    }

    

    //初始化数据
    public static ArrayList<Student_message> message = new ArrayList<Student_message>();
//    static Student_message message[] =new Student_message[10000];
    static int studentcount=0;


    //刷新列表
    public static void Updatelist(){
        data.clear();
        //默认按学号排序
        Collections.sort(message);

        for (int i = 0; i < message.size(); i++) {
            message.get(i).setNum(i+1);
        }

        data.addAll(message);
        tableView.setItems(data);
    }

    public static ObservableList<Student_message> data = FXCollections.observableArrayList();
    //初始化列表
    public void Initalization(){
        Student_message student_message = new Student_message();
        data.clear();
        message.add(new Student_message("2020xxxxxxxx1","kba","男","2002-02-24","内蒙古农业大学新区","134xxxxxxxx"));
        message.add(new Student_message("2020xxxxxxxx2","Dingding","男","2002-05-16","内蒙古农业大学新区","150xxxxxxxx"));
        message.add(new Student_message("2020xxxxxxxx3","Duoduo","男","2002-09-07","内蒙古农业大学新区","156xxxxxxxx"));
        message.add(new Student_message("2020xxxxxxxx4","L","男","2002-07-02","内蒙古农业大学新区","138xxxxxxxx"));
        message.add(new Student_message("2020xxxxxxxx5","S","男","2002-09-08","内蒙古农业大学新区","+1008611"));
        message.add(new Student_message("2020xxxxxxxx6","Peiger","女","2020-12-05","内蒙古农业大学新区","156xxxxxxxx"));
        message.add(new Student_message("2020xxxxxxxx7","Z","男","2001-11-14","内蒙古农业大学","133xxxxxxxx"));
        message.add(new Student_message("2020xxxxxxxx8","X","男","11.24","内蒙古农业大学新区","156xxxxxxxx"));
        message.add(new Student_message("2020xxxxxxxx9","~_~","男","1937-01-01","奥特星云","158xxxxxxxx"));


        data.addAll(message);
    }
    static Student_message temp = new Student_message("-1","1111","1111","1111","1111","1111");
    static Student_message temp1 = new Student_message("-1","1111","1111","1111","1111","1111");

    /******************************************************************************主页面****************************************************/
    private static final TableView<Student_message> tableView = new TableView<>();

    static TableColumn Serial_number = new TableColumn("序号");
//////////////////////////////////////////////////////////////////////////////////////////////

/*
    @Override
    public TableCell<S, T> call(TableColumn<S, T> param) {

        TableCell cell=new TableCell() {
            @Override
            protected void updateItem(Object item, boolean empty) {
                super.updateItem(item, empty);
                this.setText(null);
                this.setGraphic(null);
                if (!empty) {
                    int rowIndex = this.getIndex() + 1;
                    this.setText(String.valueOf(rowIndex));
                }
            }

        };
        return cell;
    }
*/
    /////////////////////////////////////////////
    /**头部按钮工具*/
    private void Top() {
        GridPane gridPane = new GridPane();
        gridPane.setAlignment(Pos.CENTER);
        gridPane.setPadding(new Insets(50,25,25,25));
        gridPane.setHgap(10);
        gridPane.setVgap(25);


        Label student_ID = new Label("学号：");
        TextField ID = new TextField();
        ID.setPrefColumnCount(8);
        Label student_name= new Label("姓名：");
        TextField name = new TextField();
        name.setPrefColumnCount(8);

        gridPane.add(student_ID,0,0);
        gridPane.add(ID,1,0);
        gridPane.add(student_name,2,0);
        gridPane.add(name,3,0);


        /********/
        /****/
        /*********************按钮事件*******************/
        int w=80;
        Button Inquire = new Button("查询",new ImageView("file:ico/find.png"));
        Inquire.setStyle(
                "-fx-background-radius:10;"
                        +"-fx-text-fill:rgba(255,179,0,0.84);"
                        +"-fx-border-radius:10;"
                        +"-fx-border-color:gray;"
                        +"-fx-border-width:2;"
        );
        Inquire.setPrefWidth(w);
        Inquire.setOnAction((ActionEvent e) -> {
            String idText = ID.getText();
            String nameText = name.getText();
            if(ID.equals("")&&name.equals("")){
                /****************需要优化*******/
                InquireHappenerror();
            }
            else {
                int flag=find_Student(idText,nameText);
                if(flag>=0) Home_Childinterface.ReviseMessage(message.get(flag));
                else if (flag==-1)NoStudent();
            }

        });


        Button Add = new Button("添加",new ImageView("file:ico/add.png"));
        Add.setStyle(
                "-fx-background-radius:10;"
                        +"-fx-text-fill:#003800;"
                        +"-fx-border-radius:10;"
                        +"-fx-border-color:gray;"
                        +"-fx-border-width:2;"
        );
        Add.setPrefWidth(w);
        Add.setOnAction((ActionEvent e) -> {
            String idText = ID.getText();
            String nameText = name.getText();

            Message_gridPane.ClearMessage();
            Home_Childinterface.AddMessage(idText,nameText);
        });

        Button Revise = new Button("修改",new ImageView("file:ico/modify.png"));
        Revise.setStyle(
                "-fx-background-radius:10;"
                        +"-fx-text-fill:blue;"
                        +"-fx-border-radius:10;"
                        +"-fx-border-color:gray;"
                        +"-fx-border-width:2;"
        );

        Revise.setPrefWidth(w);
        Revise.setOnAction((ActionEvent e) -> {
/******原页面***/
//            String idText = ID.getText();
//            String nameText = name.getText();
//            if(ID.equals("")&&name.equals("")){
//                /****************需要优化*******/
//                InquireHappenerror();
//            }
//            else {
//                int flag = find_Student(idText, nameText);
//                if (flag >=0) {
//                    Home_Childinterface.ReavmpMessage(message.get(flag));
//                    Updatelist();
//                }
//                else if(flag==-1)NoStudent();
//                //查询*修改
//            }

            //****************************************************************

            if(temp.equals(temp1)){
                Chickerror();
            }
            else {
                Home_Childinterface.ReavmpMessage(temp);
                Updatelist();
            }
            //*********************************************************************************
        });

        Button Delete = new Button("删除",new ImageView("file:ico/del.png"));
        Delete.setStyle(
                "-fx-background-radius:10;"
                        +"-fx-text-fill:#b40000;"
                        +"-fx-border-radius:10;"
                        +"-fx-border-color:gray;"
                        +"-fx-border-width:2;"
        );
        Delete.setPrefWidth(w);
        Delete.setOnAction((ActionEvent e) -> {

//            String idText = ID.getText();
//            String nameText = name.getText();
//            if(ID.equals("")&&name.equals("")){
//                /****************需要优化*******/
//                InquireHappenerror();
//            }
//            else {
//                int flag = find_Student(idText, nameText);
//                if (flag >=0) {
//                    //是否删除
//                    /*************************/
//                    Deletestage.setTitle("删除");
//                    Deletestage.setResizable(false);
//                    BorderPane borderPane1 = new BorderPane();
//                    String text = "确认删除该学生？";
////        Label label = new Label(Text);
//                    Text text1 = new Text(text);
//                    text1.setFont(new Font(30));
//                    text1.setFill(Paint.valueOf("RED"));
//                    HBox hBox = new HBox(40);
//                    hBox.setPrefHeight(30);
//                    Button sure1 = new Button("删除", new ImageView("File:ico/del.png"));
//                    Button back = new Button("返回", new ImageView("File:ico/logout.png"));
//                    hBox.getChildren().addAll(back, sure1);
//
//
//                    back.setOnAction((ActionEvent a) -> {
//                        Deletestage.close();
//                    });
//                    sure1.setOnAction((ActionEvent a) -> {
////                        Homepage.data.remove(message.get(flag));
//                        Homepage.message.remove(message.get(flag));
//                        Homepage.DeleteSure();
//                        Updatelist();
//                        Deletestage.close();
//                    });
//
//                    borderPane1.setCenter(text1);
////        text1.setAlignment(Pos.CENTER);
//                    borderPane1.setBottom(hBox);
//                    hBox.setAlignment(Pos.CENTER);
//                    Scene scene21 = new Scene(borderPane1,400,300);
//                    Deletestage.getIcons().add(new Image("File:title/error.png"));
//                    Deletestage.setScene(scene21);
//                    Deletestage.show();
//
//                    /**************************************/
//                }
//                else if(flag==-1)NoStudent();
//                //查询*修改
//            }

            if (temp.equals(temp1)){
                Chickerror();
            }
            else {
                Deletestage.setTitle("删除");
                Deletestage.setResizable(false);
                BorderPane borderPane1 = new BorderPane();
                String text = "确认删除该学生？";
                Text text1 = new Text(text);
                text1.setFont(new Font(30));
                text1.setFill(Paint.valueOf("RED"));
                HBox hBox = new HBox(40);
                hBox.setPrefHeight(130);
                Button sure1 = new Button("删除", new ImageView("File:ico/del.png"));
                Button back = new Button("返回", new ImageView("File:ico/logout.png"));
                hBox.getChildren().addAll(back, sure1);
                back.setOnAction((ActionEvent a) -> {
                    Deletestage.close();
                });
                sure1.setOnAction((ActionEvent a) -> {
//                        Homepage.data.remove(message.get(flag));
                    Homepage.message.remove(temp);
                    Homepage.DeleteSure();
                    Updatelist();
                    temp=temp1;
                    Deletestage.close();
                });

                borderPane1.setCenter(text1);
//        text1.setAlignment(Pos.CENTER);
                borderPane1.setBottom(hBox);
                hBox.setAlignment(Pos.CENTER);
                Scene scene21 = new Scene(borderPane1,400,300);
                Deletestage.getIcons().add(new Image("File:title/error.png"));
                Deletestage.setScene(scene21);
                Deletestage.show();

            }

        });

        gridPane.add(Inquire,4,0);
        gridPane.add(Add,5,0);
        gridPane.add(Revise,6,0);
        gridPane.add(Delete,7,0);


        borderPane.setTop(gridPane);
        BorderPane.setAlignment(gridPane, Pos.TOP_CENTER);
    }

    /**中间表格部分*/
    private   void Center() {
        tableView.setMaxWidth(824);

//        TableColumn tableColumn = new TableColumn();
//        tableColumn.setCellValueFactory();

        //tableView 表头
        /*********************************************/
        Serial_number.setPrefWidth(50);
        Serial_number.setCellValueFactory(
                new PropertyValueFactory<>("num"));

        TableColumn ID = new TableColumn("学号");
        ID.setPrefWidth(130);
        ID.setCellValueFactory(
                new PropertyValueFactory<>( "ID"));

        TableColumn name = new TableColumn("姓名");
        name.setPrefWidth(100);
        name.setCellValueFactory(
                new PropertyValueFactory<>( "name"));

        TableColumn gender = new TableColumn("性别");
        gender.setPrefWidth(48);
        gender.setCellValueFactory(
                new PropertyValueFactory<>( "gender"));

        TableColumn birthday = new TableColumn("生日");
        birthday.setPrefWidth(150);
        birthday.setCellValueFactory(
                new PropertyValueFactory<>( "birthday"));

        TableColumn address = new TableColumn("家庭地址");
        address.setPrefWidth(204);
        address.setCellValueFactory(
                new PropertyValueFactory<>( "address"));

        TableColumn phone = new TableColumn("联系电话");
        phone.setPrefWidth(110);
        phone.setCellValueFactory(
                new PropertyValueFactory<>( "phone"));

        TableColumn chick = new TableColumn(" ");
        chick.setCellFactory(ChoiceBoxTableCell.forTableColumn(chick));
        chick.setPrefWidth(30);

        ToggleGroup group = new ToggleGroup();
        /**************************************************/
        chick.setCellFactory((col) -> {
            TableCell<Student_message, String> cell = new TableCell<Student_message, String>() {

                @Override
                public void updateItem(String item, boolean empty) {
                    super.updateItem(item, empty);
                    this.setText(null);
                    this.setGraphic(null);
                    TableCell<Student_message, String> that = this;

                    if (!empty) {


                        RadioButton chick = new RadioButton();
                        chick.setToggleGroup(group);
                        this.setGraphic(chick);
                        chick.selectedProperty().addListener(new ChangeListener<Boolean>() {

                            @Override
                            public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
                                temp = that.getTableView().getItems().get(that.getIndex());
                            }
                        });


//                        Button delBtn = new Button("",new ImageView("File:ico/del.png"));
//                        this.setGraphic(delBtn);
//                        delBtn.setOnMouseClicked((me) -> {
//
//                            temp = this.getTableView().getItems().get(this.getIndex());
//                            message.remove(clickedStu);
//                            Updatelist();

//                        });
                    }
                }

            };
            return cell;
        });

        /***********************************************/
        //添加初始化数据
        Initalization();
        Updatelist();
        tableView.setItems(data);

        /*改变时set表格宽度*/
        tableView.getColumns().addAll(Serial_number,ID,name,gender,birthday,address,phone,chick);
//        tableView.getColumns().addAll(Serial_number,ID,name,gender,birthday,address,phone);

        //给表格添加选中某一行的事件
//        tableView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Student_message>() {
//            @Override
//            public void changed(ObservableValue<? extends Student_message> observable, Student_message oldValue, Student_message newValue) {
//                Student_message student_message = new Student_message(newValue.getID(),newValue.getName(),newValue.getGender(),newValue.getBirthday(),newValue.getAddress(),newValue.getPhone());
//                System.out.println(student_message.toString());
//            }
//        });


        final Label label = new Label("Student Message");
        label.setFont(new Font("Arial", 20));
        VBox vBox = new VBox();
//        vBox.getChildren().addAll(label,tableView);
//        vBox.setAlignment(Pos.CENTER);
        borderPane.setCenter(tableView);
        BorderPane.setAlignment(tableView,Pos.CENTER);
    }

    /**底部*/
    private void Bottom() {
        Button imput_ = new Button("导入",new ImageView("file:ico/import.png"));
        imput_.setStyle(
                "-fx-background-radius:10;"
                        +"-fx-text-fill:#008cff;"
                        +"-fx-border-radius:10;"
                        +"-fx-border-color:gray;"
                        +"-fx-border-width:2;"
        );
        imput_.setMaxWidth(100);
        Button output_ = new Button("导出",new ImageView("file:ico/export.png"));
        output_.setStyle(
                "-fx-background-radius:10;"
                        +"-fx-text-fill:#008cff;"
                        +"-fx-border-radius:10;"
                        +"-fx-border-color:gray;"
                        +"-fx-border-width:2;"
        );


        HBox hBox = new HBox(50);
        hBox.setPrefHeight(70);
        imput_.setOnAction((ActionEvent e) -> {
            Import();
        });
        output_.setOnAction((ActionEvent e) -> {
            //等待界面;
            if(message.size()>100)//如果大于100，等待
            try {
                FXMLLoader fxmlLoader = new FXMLLoader(Homepage.class.getResource("waitingexport.fxml"));
                Scene scene = new Scene(fxmlLoader.load());
                Hintstage.setTitle("正在导出");
                Hintstage.getIcons().add(new Image("file:title/check.png"));
                //stage.initOwner();需要禁用主窗口
                Hintstage.setResizable(false);
                Hintstage.setScene(scene);
                Hintstage.show();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            //导出数据
            Output();

            //关闭等待界面
            Hintstage.close();
        });
        hBox.getChildren().addAll(imput_,output_);
        borderPane.setBottom(hBox);
        hBox.setAlignment(Pos.CENTER);
        BorderPane.setAlignment(hBox,Pos.BOTTOM_CENTER);

    }

    private void Side(){
        VBox vBoxLift = new VBox();
        vBoxLift.setPrefWidth(10);
        VBox vBoxRight = new VBox();
        vBoxRight.setPrefWidth(11);
        borderPane.setLeft(vBoxLift);
//        vBoxLift.setAlignment(Pos.CENTER);
//        BorderPane.setAlignment(vBoxLift,Pos.BASELINE_LEFT);
        borderPane.setLeft(vBoxRight);
//        vBoxRight.setAlignment(Pos.CENTER);
//        BorderPane.setAlignment(vBoxLift,Pos.BASELINE_RIGHT);
    }
    /***********************************************************************************************************************************/





    /**提示输出信息**/
    private void InquireHappenerror() {
        try {
            FXMLLoader fxmlLoader = new FXMLLoader(Homepage.class.getResource("nocin.fxml"));
            Scene scene = new Scene(fxmlLoader.load());
            Hintstage.setTitle("错误");
            Hintstage.getIcons().add(new Image("File:title/error.png"));
            //stage.initOwner();需要禁用主窗口
            Hintstage.setResizable(false);
            Hintstage.setScene(scene);
            Hintstage.show();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

    /**核对学生信息*/
    int find_Student(String ID,String name){
        if(ID.equals("")&&name.equals("")){
            /****************需要优化*******/
            InquireHappenerror();
            return -2;
        }
        else if(ID.equals("")){ //name查询
            for(int i = 0; i < message.size(); i++)
                if(message.get(i).getName().equals(name)) {
                    return i;
                }
        }
        else if(name.equals("")){
            for(int i = 0; i < message.size(); i++)
                if(message.get(i).getID().equals(ID)) {
                    return i;
                }
        }
        else {//都查找
            for(int i = 0; i < message.size(); i++)
                if(message.get(i).getName().equals(name) && message.get(i).getID().equals(ID)) {
                    return i;
                }
        }
        return -1;
    }

    /**无该学生**/
    public static void NoStudent() {
        try {
            FXMLLoader fxmlLoader = new FXMLLoader(Homepage.class.getResource("nofind.fxml"));
            Scene scene = new Scene(fxmlLoader.load());

            Hintstage.setTitle("错误");
            Hintstage.getIcons().add(new Image("File:title/error.png"));
            //stage.initOwner();需要禁用主窗口
            Hintstage.setResizable(false);
            Hintstage.setScene(scene);
            Hintstage.show();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

    /**删除成功*/
    public static void DeleteSure() {
        try {
            FXMLLoader fxmlLoader = new FXMLLoader(Homepage.class.getResource("delsucceed.fxml"));
            Scene scene = new Scene(fxmlLoader.load());
            Hintstage.setTitle("删除成功");
            Hintstage.getIcons().add(new Image("File:title/del.png"));
            //stage.initOwner();需要禁用主窗口
            Hintstage.setResizable(false);
            Hintstage.setScene(scene);
            Hintstage.show();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

    /**导出成功*/
    public static void Outputsucceed() {
        try {
            FXMLLoader fxmlLoader = new FXMLLoader(Homepage.class.getResource("Outputsucceed.fxml"));
            Scene scene = new Scene(fxmlLoader.load());
            Hintstage.setTitle("成功");
            Hintstage.getIcons().add(new Image("File:title/check.png"));
            //stage.initOwner();需要禁用主窗口
            Hintstage.setResizable(false);
            Hintstage.setScene(scene);
            Hintstage.show();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

    /**选择错误页面*/
    public static void Chickerror() {
        try {
            FXMLLoader fxmlLoader = new FXMLLoader(Homepage.class.getResource("chickerror.fxml"));
            Scene scene = new Scene(fxmlLoader.load());
            Hintstage.setTitle("错误");
            Hintstage.getIcons().add(new Image("File:title/error.png"));
            //stage.initOwner();需要禁用主窗口
            Hintstage.setResizable(false);
            Hintstage.setScene(scene);
            Hintstage.show();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
    /**导入界面*/
    public static void Imputsucceed(int succeed ,int error ,int repetition) {

        Hintstage.setTitle("导入完成");
        Hintstage.setResizable(false);
        BorderPane borderPane = new BorderPane();

        Text text1 = new Text("导入完成:\n"+"       "+"成功："+succeed+",失败："+error+","+"重复："+repetition+"。");

        text1.setFont(new Font("Verdana",25));
        text1.setFill(Color.GREEN);
//        text1.setFill(Paint.valueOf("RED"));
        HBox hBox = new HBox(40);
        hBox.setPrefHeight(130);
        Button sure = new Button("确定",new ImageView("File:ico/correct.png"));
        sure.setOnAction((ActionEvent e) -> {
            Hintstage.close();
        });
        hBox.getChildren().add(sure);
        borderPane.setCenter(text1);
//        text1.setAlignment(Pos.CENTER);
        borderPane.setBottom(hBox);
        hBox.setAlignment(Pos.CENTER);
        Scene scene = new Scene(borderPane,400,300);
        Hintstage.getIcons().add(new Image("File:title/data-arrival.png"));
        Hintstage.setScene(scene);
        Hintstage.show();
    }

    /**确认删除页面*/
    public static void DeleteStudencountue(Student_message student_message){

        Hintstage.setTitle("删除");
        Hintstage.setResizable(false);
        BorderPane borderPane = new BorderPane();
        String text ="确认删除该学生？";
//        Label label = new Label(Text);
        Text text1 = new Text(text);
        text1.setFont(new Font(30));
        text1.setFill(Paint.valueOf("RED"));
        HBox hBox = new HBox(40);
        Button sure = new Button("删除",new ImageView("File:ico/del.png"));
        Button back = new Button("返回",new ImageView("File:ico/logout.png"));
        hBox.getChildren().addAll(back,sure);
        back.setOnAction((ActionEvent e) -> {
            Hintstage.close();
        });
        sure.setOnAction((ActionEvent e) -> {
            data.remove(student_message);
            message.remove(student_message);
            DeleteSure();
            Hintstage.close();
        });

        borderPane.setCenter(text1);
        borderPane.setBottom(hBox);
        hBox.setAlignment(Pos.CENTER);
        Scene scene = new Scene(borderPane,400,300);
        Hintstage.getIcons().add(new Image("File:title/error.png"));
        Hintstage.setScene(scene);
        Hintstage.show();
    }


    /**监听表格*/
    public static void jiance(){
    }

    /**查重*/
    static boolean Contains(Student_message student_message) {
        for (int i = 0; i < message.size(); i++) {
            if(message.get(i).equals(student_message))return false;
        }
        return true;
    }

    /**导入数据*/
    public void Import() {
        ArrayList<String> s = FileIO.fileRead();
        int succeed=0,error=0,repetition=0;
        for(int i = 0 ; i < s.size() ; i++){
            String a[] = s.get(i).split(",");

            boolean falg = true;//文档中信息是否符合要求
            if(a.length<6)falg=false;
            for (int j = 0; j < a.length; j++) {
                if(a[j].equals("")){
                    falg=false;
                    break;
                }
            }

            if(falg){
                Student_message student_message = new Student_message();
                student_message.setMessage(s.get(i));
                if(Contains(student_message)){
                    message.add(student_message);
                    data.add(student_message);
                    succeed++;
                }
                else repetition++;
            }
            else error++;//添加失败
        }
        Updatelist();
        Imputsucceed(succeed ,error ,repetition);
//        System.out.println("文件导入成功  "+"成功："+succeed+" 失败："+error+" 重复："+repetition);
    }

    /**导出数据*/
    public void Output() {
        StringBuilder s = new StringBuilder();
        LocalDateTime time = LocalDateTime.now();//获取当前时间
        s.append("——————————————————————导出于："+time.toString()+"————————————————————\n");
        for(int i=0;i<message.size();i++) {
            s.append(message.get(i).toString()+"\n");
        }
        s.append("________________________________________________________________________\n\n");
        String ss = new String();
        /****测试**/
//        System.out.println(s.toString());
        ss = s.toString();
        FileIO.fileWrite(ss);
        Outputsucceed();
    }

    public static void main(String[] args) {
        Application.launch();
    }
}
